<?
#####################################################
#  COPYRIGHT NOTICE
#####################################################
# In the following statements, the term "this 
# program" refers to all files associated with the
# execution and distribution of Adtrackz.
#
# This Program is Copyright 2004 Jonah Klimack.
# All Rights Reserved. 
#
# Selling the code for this program, modifying 
# and/or redistributing the code for this program
# in part or in whole over the Internet or in any 
# other medium is expressly forbidden. Violators
# will be prosecuted to the fullest extent of the law
# Copyright and header information may not be
# modified.
#
# This program is distributed "as is" and without 
# warranty of any kind, either express or implied.
# In no event shall the liability of Jonah Klimack 
# for any damages, losses and/or causes of 
# action exceed the total amount paid by the 
# user for this software.		
#####################################################
# DO NOT MODIFY ANYTHING IN THIS FILE
#####################################################


require "header.php";

?>

<p class="small" align="left">
Cloak > View/Edit
</p>
<p class="heading">
Your Redirect Files
</p>

<p>
<u>List of Current Files</u>
</p>

<p>
Here's a list of all redirect files you have created. You can delete them from your server by using this interface.
</p>

<?

//USER SELECTED AND WANTS TO DELETE THEM
if ($submit)
{
	//delete files
	//delete mysql entries
	$ftp_info = mysql_fetch_row(mysql_query("select ftp_user, ftp_pass from adtrackz_login"));
	$user = $ftp_info[0];
	$pass = $ftp_info[1];
	$ftp_server = ereg_replace("www", "ftp", $domain);
	if (!$check)
		error("You did not select any files to delete.");
	else
	{
		$msg = "";
		if (!$conn_id = @ftp_connect($ftp_server))
			fatal_error("Couldn't connect to the ftp server: $ftp_server. Line: ".__LINE__);		
		if (@ftp_login($conn_id, $user, $pass) === FALSE)
			fatal_error("Couldn't login to $ftp_server with username: $user and password: $pass. If your FTP information has changed you can modify it by selecting \"Update Profile\" in the Help menu. Line: ".__LINE__);
		foreach ($check as $c)
		{
			$filename = mysql_fetch_row(mysql_query("select filename from adtrackz_redirects where ID='$c'"));
			$ftpfile = $filename[0];
			if (!@ftp_delete($conn_id, $ftpfile))
				fatal_error("Couldn't delete $ftpfile. ");
			mysql_query("delete from adtrackz_redirects where ID='$c'");	
			$msg .= "$filename[0] has been deleted from your server.<br>";
		}
		ftp_close($conn_id);
		alert($msg);
	}
}

$redirects = mysql_query("select * from adtrackz_redirects order by filename asc");
if (!mysql_num_rows($redirects))
	echo "<br><br><table align=center><tr><td>There are no redirect files to display. <a href=cloak.php>Click here</a> to add a new redirect file.</td></tr></table>";
else
{
?>
	<form action="mcloak.php" method="post">
	<table width="580" border="1" cellspacing="0" cellpadding="5" align="center" bordercolor="#e0e0e0">
	<tr>
		<td class="tbhead1">Campaign</td>
		<td class="tbhead1">Sub</td>
		<td class="tbhead1">Filename</td>
		<td class="tbhead1">Encrypt</td>
		<td class="tbhead1">Sticky</td>
		<td class="tbhead1">Delete</td>
	</tr>
	<?
	while ($r = mysql_fetch_row($redirects))
	{
		$campaign = mysql_fetch_row(mysql_query("select adcode from adtrackz_campaigns where ID='$r[1]'"));
		$sub = ( !$r[2] ? "-" : $r[2] );	
		if ($r[4])
			$encrypt = "yes";
		else
			$encrypt = "no";
		if ($r[5])
			$cloak = "yes";
		else
			$cloak = "no";

		//convert server path to http file so they can click on it here
		 list ($cut, $wwwpath) = split($basedir, $r[3]);
		$link = "http://".$domain.$wwwpath;				

print <<<END
<tr>
	<td class="tb2">$campaign[0]</td>
	<td class="tb2">$sub</td>
	<td class="tb2"><a href=$link target=_new>$link</a></td>
	<td class="tb2">$encrypt</td>
	<td class="tb2">$cloak</td>
	<td class="tb2"><input type="checkbox" name="check[]" value="$r[0]"></td>
</tr>
END;
	}
?>
</table>
<br>
<center>
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" name="submit" value="Delete Selected"  >
</center>
</form>
<br>

<?
}
require "footer.php";
?>